#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QStandardItemModel>
#include <QStandardItem>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 创建列表模型
    QStandardItemModel* listModel = new QStandardItemModel(this);
    QStandardItem* listParent = listModel->invisibleRootItem();
    QList<QStandardItem*> itemList;
    itemList << new QStandardItem("one")
             << new QStandardItem("two")
             << new QStandardItem("three")
             << new QStandardItem("four");
    listParent->appendRows(itemList);
    ui->listView->setModel(listModel);

    // 创建表格模型
    QStandardItemModel* tableModel = new QStandardItemModel(this);
    QStandardItem* tableParent = tableModel->invisibleRootItem();
    tableParent->setRowCount(3);
    tableParent->setColumnCount(4);
    for(int row = 0; row < 3; row++){
        for(int column = 0; column < 4; column++){
            tableParent->setChild(row, column, new QStandardItem(QString("%1").arg((row + 1) * 10 + (column + 1))));
        }
    }
    ui->tableView->setModel(tableModel);

    // 创建树形模型
    QStandardItemModel* treeModel = new QStandardItemModel(this);
    QStandardItem* treeParent = treeModel->invisibleRootItem();
    QStandardItem* CItem = new QStandardItem("C盘");
    QStandardItem* DItem = new QStandardItem("D盘");
    treeParent->appendRow(CItem);
    treeParent->appendRow(DItem);

    treeParent = CItem;
    QStandardItem* windowsItem = new QStandardItem("windows");
    QStandardItem* programesItem = new QStandardItem("programes Files");
    treeParent->appendRow(windowsItem);
    treeParent->appendRow(programesItem);

    treeParent = DItem;
    QStandardItem* movieItem = new QStandardItem("电影");
    QStandardItem* gamesItem = new QStandardItem("游戏");
    treeParent->appendRow(movieItem);
    treeParent->appendRow(gamesItem);

    ui->treeView->setModel(treeModel);
}

MainWindow::~MainWindow()
{
    delete ui;
}
